<template>
  <div class="inside-page">
    <div class="choice-wrap">
      <div class="choice-wrap-container">
        <div class="wrap-left">
          <img src="" />
        </div>
        <div class="wrap-right">
          <p class="wrap-name">
            <span class="name">{{ info.name }}</span>
            <span class="corner">线上专场</span>
          </p>
          <p class="pro">主办单位：{{ info.for_name }}</p>
          <div class="wrap">
            <p>
              <i class="iconfont icon-map"></i>
              <span>地址：线上</span>
            </p>
          </div>
          <div class="time">
            <p>
              <span>双选会时间：{{ info.push_end_time }}</span>
            </p>
          </div>
        </div>
        <div class="company-data">
          <div class="data">
            <p class="num">{{ info.attend_company }}</p>
            <p class="text">参会单位</p>
          </div>
          <div class="data">
            <p class="num">{{ info.operating_number }}</p>
            <p class="text">提供岗位</p>
          </div>
          <div class="data">
            <p class="num">{{ info.attend_person }}</p>
            <p class="text">点击量</p>
          </div>
          <div class="submit">
            <button
              v-if="subState === 1"
              class="confirm"
              type="button"
              @click="submit"
            >
              加入双选会
            </button>
            <button
              v-if="subState === 2"
              class="confirm"
              type="button"
              @click="submit"
            >
              立即报名
            </button>
            <div class="disabled" v-else-if="subState === 3">已报名</div>
          </div>
        </div>
      </div>
    </div>
    <div class="choice-detail content">
      <p class="detail-title">双选会简介</p>
      <div class="intro">
        <img :src="info.image" />
      </div>
      <div class="intro-text">
        <p class="con">{{ intro }}</p>
        <p v-if="showToggle" class="toggle-btn" @click="toggleText">
          {{ toggleActive ? '收起' : '展开' }}
        </p>
      </div>
      <p class="detail-title">招聘企业</p>
      <div class="pos-filter">
        <p>职位筛选：</p>
        <client-only>
          <el-select
            v-model="cityid"
            clearable
            @change="toFilter"
            placeholder="选择工作地点"
          >
            <el-option
              v-for="item in search.city"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </client-only>
        <client-only>
          <el-select
            v-model="industry"
            clearable
            @change="toFilter"
            placeholder="选择行业"
          >
            <el-option
              v-for="item in search.industry"
              :key="item.id"
              :label="item.tagname"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </client-only>
        <client-only>
          <el-select
            v-model="posttypeid"
            clearable
            @change="toFilter"
            placeholder="选择职能"
          >
            <el-option
              v-for="item in search.postType"
              :key="item.id"
              :label="item.tagname"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </client-only>
      </div>
      <div class="choice-list">
        <div
          class="choice-item clearfix"
          v-for="(j, k) in jobList"
          :key="j.id"
          @click="jumpTo(j)"
        >
          <div class="choice-pos">
            <div class="text">
              <span class="choice-name" :title="j.cname">{{ j.cname }}</span>
            </div>
            <div class="wrap">
              <p>
                <i class="iconfont icon-company"></i><span>{{ j.attrid }}</span>
              </p>
              <p>
                <i class="iconfont icon-people"></i><span>{{ j.sizeid }}</span>
              </p>
            </div>
          </div>
          <div class="choice-type">
            <p class="name">{{ j.industryid }}</p>
            <div class="text">
              <span
                class="tag"
                v-for="(v, i) in j.welfare"
                :key="'welfare_' + i"
                >{{ v }}</span
              >
            </div>
          </div>
          <div class="choice-num">
            <p class="num">{{ checkNum(k) }}</p>
            <p class="text">序号</p>
          </div>
          <div class="choice-job">
            <p class="pos">
              <span>{{ j.place_num }}个工作机会</span>
              <span>{{ j.job_num }}个职位</span>
            </p>
            <p class="time">
              <i class="iconfont icon-time"></i>
              <span>申请截止：{{ j.end_time }}</span>
            </p>
          </div>
          <div class="choice-logo">
            <img :src="j.logo" />
          </div>
        </div>
      </div>
      <client-only>
        <el-pagination
          hide-on-single-page
          background
          prev-text="上一页"
          next-text="下一页"
          layout="prev, pager, next"
          :current-page="pageNo"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
        />
      </client-only>
    </div>
  </div>
</template>

<script>
import { getChoiceDetail } from '@/api/choice';

export default {
  asyncData: ({ req }) => ({
  }),
  components: {},
  data () {
    return {
      subState: 1,
      info: {

      },
      showToggle: false,
      intro: '',
      toggleActive: false,
      jobList: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      search: {
        city: [],
        industry: [],
        postType: [],
      },
      cityid: '',
      industry: '',
      posttypeid: '',
    }
  },
  head () {
    return {
      titleTemplate: (titleChunk) => {
        return `${titleChunk} - 大学生找工作、找实习`;
      }
    }
  },
  created () {
    this.id = this.$route.query.id;
    this.fetchData();
  },
  mounted () {
  },
  watch: {
    $route: {
      handler (val, oldVal) {
        // this.getPageArticle(val.query.area, val.query.id);
      },
      deep: true
    }
  },
  computed: {
    checkNum () {
      return (num) => {
        return num + 1 < 10 ? '0' + (num + 1) : num + 1;
      }
    }
  },
  methods: {
    checkIntro () { // 检查公司简介
      const originIntro = this.info.desc || '';
      originIntro.length >= 125
        ? (this.intro = originIntro.slice(0, 125) + '...') && (this.showToggle = true)
        : this.intro = originIntro
    },
    toggleText () {
      this.toggleActive = !this.toggleActive;
      this.toggleActive ? (this.intro = this.info.desc) : (this.intro = this.info.desc.slice(0, 125) + '...');
    },
    handleCurrentChange (val) {
      this.pageNo = val;
      this.fetchData();
    },
    jumpTo (obj) {
      this.$router.push({
        path: '/company/detail',
        query: { id: obj.id }
      })
    },
    submit () {
      this.subState = 2;
    },
    toFilter () {
      this.pageNo = 1;
      this.fetchData();
    },
    async fetchData () {
      await getChoiceDetail({
        id: this.id,
        cityid: this.cityid,
        industry: this.industry,
        posttypeid: this.posttypeid,
        page: this.pageNo,
      }).then(res => {
        if (res.code === 200) {
          this.info = res.data.info;
          this.jobList = res.data.list;
          this.search = res.data.search;
          this.checkIntro();
        } else {
          this.$message.error(res.msg);
        }
      }).catch(err => {
        console.error(err)
        this.$message.error(err);
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.inside-page {
  width: 100%;
  position: relative;
  .choice-wrap {
    width: 100%;
    height: 220px;
    padding-top: 40px;
    background: #f6f7f8;
    position: relative;
    .choice-wrap-container {
      width: $base-width;
      margin: 0 auto;
      position: relative;
      .wrap-left {
        float: left;
        margin-top: 5px;
        height: 140px;
        width: 140px;
        overflow: hidden;
        background: #fff;
        border-radius: 8px;
        text-align: center;
        img {
          height: 140px;
        }
      }
      .wrap-right {
        float: left;
        margin-left: 20px;
        position: relative;
        .wrap-name {
          line-height: 40px;
          .name {
            font-size: 36px;
            color: #24292f;
          }
          .corner {
            vertical-align: top;
            display: inline-block;
            margin-left: 5px;
            width: 70px;
            height: 24px;
            line-height: 22px;
            font-size: 12px;
            text-align: center;
            border-radius: 4px;
            background: rgba(71, 113, 220, 0.3);
            color: $base-color;
            border: 1px solid $base-color;
          }
        }
        .pro {
          margin: 10px 0;
          font-size: 14px;
          color: #999;
        }
        .wrap {
          p {
            margin-right: 30px;
            display: inline-block;
            line-height: 20px;
            vertical-align: middle;
            i {
              color: $base-color;
              font-size: 16px;
              vertical-align: middle;
            }
            span {
              vertical-align: middle;
              font-size: 14px;
              color: #666;
            }
          }
          .money {
            color: $base-color-important;
            font-size: 18px;
            line-height: 20px;
          }
        }
        .time {
          padding-left: 15px;
          margin-top: 10px;
          position: relative;
          height: 20px;
          line-height: 20px;
          i,
          span {
            margin-right: 10px;
            font-size: 14px;
            color: #666;
          }
          &::before {
            content: '';
            height: 14px;
            width: 2px;
            background: $base-color;
            position: absolute;
            left: 2px;
            top: 3px;
          }
        }
      }
      .company-data {
        position: absolute;
        right: 0;
        top: 20px;
        .data {
          float: left;
          text-align: center;
          padding-left: 30px;
          &:first-child {
            padding-left: 0;
          }
          .num {
            font-size: 36px;
            color: $base-color;
          }
          .text {
            font-size: 14px;
            color: #999;
          }
        }
        .submit {
          margin-top: 80px;
          button {
            width: 190px;
          }
          .disabled {
            display: inline-block;
            height: 45px;
            line-height: 43px;
            width: 150px;
            margin: 0 20px;
            border: 1px solid #ccc;
            border-radius: 6px;
            font-size: 16px;
            background: #ccc;
            color: #f1f1f1;
            cursor: not-allowed;
          }
        }
      }
    }
  }

  .choice-detail {
    position: relative;
    .intro {
      height: 280px;
      background: #ebebeb;
    }
    .intro-text {
      position: relative;
      padding: 20px 0;
      p {
        font-size: 16px;
        line-height: 32px;
      }
      .con {
        color: #666;
      }
      .toggle-btn {
        position: absolute;
        right: 0;
        bottom: 20px;
        color: $base-color;
        &:hover {
          cursor: pointer;
          color: $base-color-hover;
        }
      }
    }
    .pos-filter {
      height: 50px;
      line-height: 40px;
      padding-top: 10px;
      p {
        float: left;
      }
      ::v-deep .el-input__inner {
        height: 30px;
        line-height: 30px;
      }
    }
  }

  .choice-list {
    margin: 20px auto;
    .choice-item {
      height: 120px;
      width: 100%;
      border: 1px solid #ebebeb;
      background: #fff;
      margin-bottom: 10px;
      padding-left: 40px;
      cursor: pointer;
      &:hover {
        background: #f6f7f8;
      }
      & > div {
        float: left;
      }
      .choice-pos {
        margin-top: 30px;
        line-height: 30px;
        margin-right: 20px;
        min-width: 300px;
        .choice-name {
          color: #242924;
          font-size: 18px;
          display: inline-block;
          max-width: 300px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .wrap {
          margin-top: 10px;
          p {
            margin-right: 10px;
            color: #999;
            line-height: 20px;
            font-size: 14px;
            display: inline-block;
          }
          i {
            vertical-align: middle;
            color: #999;
            margin-right: 5px;
          }
          span {
            vertical-align: middle;
            color: #999;
          }
        }
      }
      .choice-type {
        margin-top: 30px;
        width: 200px;
        line-height: 30px;
        overflow: hidden;
        .name {
          font-size: 14px;
          color: #999;
        }
        .text {
          min-height: 20px;
          margin-top: 10px;
          white-space: nowrap;
          overflow: hidden;
          .tag {
            font-size: 12px;
            color: #ccc;
            padding: 4px 8px;
            border: 1px solid #ebebeb;
            border-radius: 4px;
            margin-right: 6px;
          }
        }
      }
      .choice-num {
        margin-top: 30px;
        width: 200px;
        text-align: center;
        .num {
          color: $base-color;
          font-size: 28px;
        }
        .none {
          color: #999;
          font-size: 28px;
        }
        .text {
          font-size: 12px;
          color: #999;
        }
      }
      .choice-job {
        margin-top: 30px;
        width: 300px;
        line-height: 30px;
        .pos {
          span {
            margin-right: 20px;
            color: #666;
            font-size: 18px;
          }
        }
        .time {
          margin-top: 10px;
          i,
          span {
            color: #999;
            font-size: 14px;
          }
        }
      }
      .choice-logo {
        margin-top: 24px;
        width: auto;
        img {
          height: 74px;
        }
      }
    }
  }
}
</style>
